package com.kehutong.charge.dao;

import com.kehutong.charge.dto.ChargeBillItemAppDTO;
import com.kehutong.charge.entity.ChargeBillItems;
import org.coraframework.orm.annotation.Dao;
import org.coraframework.orm.annotation.Mapper;
import org.coraframework.orm.jdbc.Page;
import org.coraframework.orm.jdbc.execute.Condition;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Dao
public interface ChargeBillItemDao {

	/**
	 * 汇总
	 * @param condition
	 * @return
	 */
	@Mapper(
			genericType = HashMap.class,
			countSQL = "SELECT count(1) FROM( select id FROM t_charge_bill_items WHERE ${}) a",
			sql= "SELECT b.houseBillNo,b.itemBillNo,b.houseNo,b.billStatus,b.billAddress,b.chargeName,b.userNo,0 unPayAmount," +
					"b.billYearMonth,b.residentsType,sum(b.billAmount) payableAmount from t_charge_bill_items b WHERE${}"
	)
	Page<ChargeBillItemAppDTO> findHouseBillTotal(Condition... condition);

	/**
	 * 详情
	 * @param condition
	 * @return
	 */
	@Mapper(
			genericType = ChargeBillItemAppDTO.class,
			sql= "SELECT b.communityNo,b.communityName,b.houseNo,b.itemBillNo,b.payableAmount,b.billAmount," +
					"0 billItems,b.residentsType,b.chargeDate,b.billAddress,b.houseBillNo,b.itemBillNo,b.chargeName,0 unPayAmount," +
					"b.userNo,b.billYearMonth,b.feeTypeNo,b.feeTypeName,sum(b.billAmount) billAmount from t_charge_bill_items b WHERE${}"
	)
	List<ChargeBillItemAppDTO> findHouseBillUser(Condition... condition);

	/**
	 * 查询所有待缴金额
	 * @param condition
	 * @return
	 */
	@Mapper(
			genericType = HashMap.class,
			sql= "select b.communityNo,b.communityName,b.billAddress,b.houseNo,b.userNo,b.residentsType,b.billStatus,0 unPayAmount," +
					"b.chargeName,sum(IFNULL(b.payableAmount,0)) payableAmount from t_charge_bill_items b WHERE ${}"
	)
	List<ChargeBillItemAppDTO> findBillAmount(Condition... condition);


}
